package org.mybatis.spring.boot.study.dataFlow.importBDRegistrar.config;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

/**
 * @author nicky
 * @date 2021/9/1 下午6:24
 */
public class TjsBatisAutoConfiguration implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        //不应该这里注册非注册器的bean,不符合spring的生命周期规范

        //扫描注解
        Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(TjsBatisMapperScanner.class.getName());
        String[] basePackages = (String[]) annotationAttributes.get("basePackages");

        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(TjsMapperScannerRegistrar.class);
        builder.addPropertyValue("basePackages", basePackages);

        registry.registerBeanDefinition(TjsMapperScannerRegistrar.class.getName(), builder.getBeanDefinition());
    }

}
